//
//  CupAdapter.cpp
//  Cupcake
//
//  Created by luotianqiang1 on 16/12/2.
//
//

#include "CupcakeCupAdapter.h"
#include "RewardManager.h"
#include "MoveSprite.h"
#include "IAPManager.h"
#include "FoodData.h"
USING_NS_KD;
using namespace std;
EventSprite * CupcakeCupAdapter::getItem(size_t position){
        auto flavorName = file_path.at(position);
        EventSprite* s;
    string name;
    auto allfFlavor = FoodData::getAllFlavor();
    if(position<allfFlavor.size())
        name = allfFlavor.at(position);
        
    if(isFree(position)) {
            auto   temp = MoveSprite::create(file_path.at(position));
            temp->setMoveType(KDS::MoveSpriteType::kMoveEndBackStart);
            s= temp;
            temp->setRect(LQRect::create(_limit));
        }else {
            s= MyBaseAdapter::getItem(position);
           
        }
        s->setName(flavorName);
        return s;
    }

CupcakeCupAdapter::CupcakeCupAdapter() {
        
    }
    bool CupcakeCupAdapter::isFree(size_t index){
        bool flag = IAPManager::getInstance()->isFree(_currentcategory,index+1);
        if(flag){
            auto key = kRewardManager->getItemKey(_currentcategory, _currentcategory, index+1);
            auto rewardInfo = kRewardManager->getRewardInfoItem(_currentcategory, _currentcategory, index+1);
            flag = !kRewardManager->isLocked(key);
            if(!flag)
                flag = IAPManager::getInstance()->isPackagePurchased(rewardInfo.iapId);
        }
        return flag;
    }


